Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable & pass dbt-adapter-tests #16

Merged
merged 19 commits into from
Sep 25, 2020
Merged

Enable & pass dbt-adapter-tests #16

merged 19 commits into from
Sep 25, 2020

Conversation

dataders
Copy link
Contributor

this PR is blocked by dbt-labs/dbt-adapter-tests#7

changes:

  • hack to mimic functionality of DROP SCHEMA ... CASCASE to drop all views & tables on a given schema before dropping the schema itself. this was never an issue previously as it is only needed for the test suite and no materialization (that I know of) uses it.
  • custom macro for get_columns_in_query because T-SQL does not support LIMIT.
  • changed the argument of some macros... though not sure why...
    • for sqlserver__check_schema_exists(): (database, schema) to (information_schema, schema)
    • for sqlserver__drop_schema: (database_name, schema_name) to relation

FYI (@mikaelene) many of these changes will also need to be propagated upstream to dbt-sqlserver. @NandanHegde15 and I are happy to help with that.

Comment on lines +48 to +65
{% macro sqlserver__drop_schema(relation) -%}
{%- set tables_in_schema_query %}
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '{{ relation.schema }}'
{% endset %}
{% set tables_to_drop = run_query(tables_in_schema_query).columns[0].values() %}
{% for table in tables_to_drop %}
{%- set schema_relation = adapter.get_relation(database=relation.database,
schema=relation.schema,
identifier=table) -%}
{% do drop_relation(schema_relation) %}
{%- endfor %}

{% call statement('drop_schema') -%}
drop schema if exists {{ relation.without_identifier().schema }}
IF EXISTS (SELECT * FROM sys.schemas WHERE name = '{{ relation.schema }}')
BEGIN
EXEC('DROP SCHEMA {{ relation.schema }}')
END
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikaelene here is the change we made that @jtcohen6 mentioned here dbt-msft/dbt-sqlserver#54 (comment).

In our adapters we never use drop_schema(), nor does dbt-integration-tests so we never new it was problematic.

Comment on lines +5 to +12
{% macro sqlserver__get_columns_in_query(select_sql) %}
{% call statement('get_columns_in_query', fetch_result=True, auto_begin=False) -%}
select TOP 0 * from (
{{ select_sql }}
) as __dbt_sbq
{% endcall %}
{{ return(load_result('get_columns_in_query').table.columns | map(attribute='name') | list) }}
{% endmacro %}
Copy link
Contributor Author

@dataders dataders Oct 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikaelene, this is one macro we had to overwrite. perhaps this is the error you were seeing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant